package com.gzsxy.esjy.service.auth.listener;

import com.alibaba.fastjson.JSON;
import com.gzsxy.esjy.bus.event.InnerProtocolMessageEvent;
import com.gzsxy.esjy.bus.message.InnerProtocol;
import com.gzsxy.esjy.service.auth.service.UserService;
import com.gzsxy.esjy.service.base.DictionaryConstants;
import com.gzsxy.esjy.service.base.dto.request.UserRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @author xiaolong
 * @version 1.0
 * @description: 用户服务消息监听
 * @date 2022/3/3 9:03
 */
@Component
@Slf4j
public class AuthEventListener {

    @Autowired
    private UserService userService;

    @EventListener(InnerProtocolMessageEvent.class)
    public void event(InnerProtocolMessageEvent event){
        InnerProtocol message = event.getMessage();
        String cmd = message.getCmd();
        Object body = message.getBody();
        UserRequest userRequest = JSON.parseObject(JSON.toJSONString(body), UserRequest.class);
        //商家审核成功
        if (DictionaryConstants.VERIFY_SUCCESS.equals(cmd)){
            userService.verify(userRequest.getId(),DictionaryConstants.NUMBER_3);
        } else if (DictionaryConstants.VERIFY_ERROR.equals(cmd)){
            userService.verify(userRequest.getId(),DictionaryConstants.NUMBER_4);
        }
    }
}
